<template>
  <div class="jobmore ct">
    <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/yardhome', query: {yardId: yardId} }">站院首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/yardkepu', query: {yardId: yardId} }">站院科普</el-breadcrumb-item>
      <el-breadcrumb-item>河南农技大讲堂</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="s-content">
      <!-- 河南农技大讲堂 -->
      <div class="lecture-section">
        <div class="section-header">
          <div class="header-left">
            <img src="../../assets/resources/lecture-icon.png" alt="">
            <div class="header-title">河南农技大讲堂</div>
          </div>
        </div>
        <div class="lecture-cards">
          <div class="lecture-card" v-for="(item, index) in lectureData" :key="index" @click="goDetail(item)">
            <div class="card-image">
              <img :src="item.imageUrl || item.informationImage || '../../assets/resources/default-lecture.jpg'" alt="">
            </div>
            <div class="card-title">
              {{ item.title || item.informationTitle || '暂无标题' }}
            </div>
          </div>
        </div>
        
        <!-- 分页 -->
        <div class="item-page">
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 30, 50]"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ArrowRight } from '@element-plus/icons-vue'
import { pageInformation } from '@/api/home';
import { useRouter } from 'vue-router';
import { ref, onMounted, computed } from 'vue'

const router = useRouter();
const yardId = computed(() => router?.currentRoute?.value?.query.yardId);

// 河南农技大讲堂数据
const lectureData = ref([]);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);

// 获取河南农技大讲堂数据
const getLectureData = async() => {
  try {
    const params = {
      params: {
        status: true,
        courtyardId: yardId.value,
        category: 'henan_class'
      },
      page: {
        pageSize: pageSize.value,
        pageNum: currentPage.value,
      }
    }
    console.log('河南农技大讲堂请求参数:', params)
    const ret = await pageInformation(params)
    console.log('河南农技大讲堂API返回数据:', ret)
    lectureData.value = ret?.data?.list || [];
    total.value = ret?.data?.total || 0;
    console.log('处理后的数据:', lectureData.value)
  } catch (error) {
    console.error('获取河南农技大讲堂数据失败:', error)
  }
}

// 处理页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val;
  getLectureData();
}

// 处理每页数量变化
const handleSizeChange = (val) => {
  pageSize.value = val;
  currentPage.value = 1;
  getLectureData();
}

// 跳转到详情页
const goDetail = (item) => {
  router.push(`/yardkepuDetail/${item.informationId}?yardId=${yardId.value}`)
}

// 页面加载时获取数据
onMounted(() => {
  getLectureData();
})
</script>

<style lang="scss" scoped>
.jobmore {
  flex: 1;
  width: 100%;
  padding: 0 10%;
  color: #777;
  background: url('../../assets/xiaoyuan/4.jpeg') no-repeat center center / cover;

  .head-nav {
    display: flex;
    align-items: center;
    font-size: 24px;
    padding: 40px 0 30px;
  }
  
  .s-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 1000px;
    width: 100%;
    font-size: 24px;
  }

  // 通用标题栏样式
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 20px;
    position: relative;
    
    &::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 1px;
      background-color: #e0e0e0;
    }
    
    .header-left {
      display: flex;
      align-items: center;
      img {
        width: 50px;
        height: 50px;
        margin-right: 20px;
        object-fit: contain;
      }
      .header-title {
        font-size: 32px;
        font-weight: bold;
        color: #333;
      }
    }
  }

  // 河南农技大讲堂样式
  .lecture-section {
    margin-bottom: 60px;
    
    .lecture-cards {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 20px;
      padding-bottom: 10px;
      margin-top: 30px;
      
      .lecture-card {
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        cursor: pointer;
        transition: transform 0.2s;
        height: 420px;
        
        &:hover {
          transform: translateY(-5px);
        }
        
        .card-image {
          height: 350px;
          overflow: hidden;
          
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        
        .card-title {
          font-size: 16px;
          font-weight: bold;
          color: #333;
          padding: 0 15px;
          text-align: center;
          line-height: 1.2;
          height: 60px;
          display: flex;
          align-items: center;
          justify-content: center;
          word-break: break-word;
          overflow: hidden;
          box-sizing: border-box;
        }
      }
    }
    
    .item-page {
      display: flex;
      justify-content: center;
      margin-top: 40px;
    }
  }
}
</style>
